<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        /**
        * @param {number[]} prices
        * @return {number}
        */
        var maxProfit = function(prices) {
            if(prices.length<=1)
            {
                return 0;
            }
            var min=prices[0];
            var ans=0;
            for(var i=1;i<prices.length;i++)
            {
                if(min>prices[i]){
                    min=prices[i];
                }else{
                    ans=Math.max(ans,prices[i]-min);
                }
            }
            return ans;
        };
    </script>
</body>
</html>